package com.tenqian.utils;

import com.yunpian.sdk.YunpianClient;
import com.yunpian.sdk.model.Result;
import com.yunpian.sdk.model.SmsSingleSend;

import java.util.Map;

public class SendMessageUtil {
    static YunpianClient clnt = new YunpianClient("dc188a5759321ae2b6439a46b58b9f56").init();

    public static int singleSend(String telephone, String text) {
        //发送短信API
        Map<String, String> param = clnt.newParam(2);
        param.put(YunpianClient.MOBILE, telephone);
        param.put(YunpianClient.TEXT, text);
        Result<SmsSingleSend> r = clnt.sms().single_send(param);
        //获取返回结果，返回码:r.getCode(),返回码描述:r.getMsg(),API结果:r.getData(),其他说明:r.getDetail(),调用异常:r.getThrowable()
        return r.getCode();
        //账户:clnt.user().* 签名:clnt.sign().* 模版:clnt.tpl().* 短信:clnt.sms().* 语音:clnt.voice().* 流量:clnt.flow().* 隐私通话:clnt.call().*

        //释放clnt
        //clnt.close();
    }

    public static int sendCode(String telephone, String code) {
        return singleSend(telephone, "【腾乾网络】您的验证码是" + code + "。如非本人操作，请忽略本短信");
    }

}
